package com.hutao.medical.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hutao.medical.common.util.JsonUtils;
import com.hutao.medical.common.util.StringUtil;
import com.hutao.medical.dataSource.TargetDataSource;
import com.hutao.medical.mapper.hospitalnote.HospitalNoteBasicJsonMapper;
import com.hutao.medical.query.FullTextVO;
import com.hutao.medical.service.HospitalNoteService;
@Service
public class HospitalNoteServiceImpl implements HospitalNoteService{

	@Autowired
	private HospitalNoteBasicJsonMapper hospitalNoteBasicJsonMapper;
	
	@Autowired
	private com.hutao.medical.mapper.retrieval.MedRecordRetrievalMapper medRecordRetrievalMapper;
	
	@TargetDataSource(name="ds1")
	@Transactional(readOnly=true)
	@Override
	public List<String> getFullTextSearch() {
		
		return hospitalNoteBasicJsonMapper.getFullTextSearch();
	}

	
	@TargetDataSource(name="ds1")
	@Transactional(readOnly=true)
	@Override
	public List<Map<String,Object>> getFullText(List<FullTextVO> fulltextVoList) {
		
		for (FullTextVO fullTextVO : fulltextVoList) {
			
             if("1".equals(fullTextVO.getOperationalName())){
            	 fullTextVO.setOperationalName("=");
            	 fullTextVO.setParameterValue("\'"+StringUtil.handleJsonParam(fullTextVO.getParameterValue())+"\'");
             }else if("2".equals(fullTextVO.getOperationalName())){
            	 fullTextVO.setOperationalName("<");
            	 fullTextVO.setParameterValue("\'"+StringUtil.handleJsonParam(fullTextVO.getParameterValue())+"\'");
             }else if("3".equals(fullTextVO.getOperationalName())){
            	 fullTextVO.setOperationalName(">");
            	 fullTextVO.setParameterValue("\'"+StringUtil.handleJsonParam(fullTextVO.getParameterValue())+"\'");
             }else if("4".equals(fullTextVO.getOperationalName())){
            	 fullTextVO.setOperationalName("<=");
            	 fullTextVO.setParameterValue("\'"+StringUtil.handleJsonParam(fullTextVO.getParameterValue())+"\'");
             }else if("5".equals(fullTextVO.getOperationalName())){
            	 fullTextVO.setOperationalName(">=");
            	 fullTextVO.setParameterValue("\'"+StringUtil.handleJsonParam(fullTextVO.getParameterValue())+"\'");
             }/*else if("6".equals(fullTextVO.getOperationalName())){
            	 fullTextVO.setOperationalName("like");
            	 fullTextVO.setParameterValue("\'"+StringUtil.handleJsonParam(fullTextVO.getParameterValue())+"%\'");
             }*/
		}
		List<Map<String,Object>> jsonFullTextList = new ArrayList<>();
		List<String> fulltextList = medRecordRetrievalMapper.getFullText(fulltextVoList);
		for (String fulltext : fulltextList) {
			jsonFullTextList.add(JsonUtils.jsonToPojo(fulltext, Map.class));
		}
		
		
		
		return jsonFullTextList;
	}

}
